package yyh.guanganmen.server;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.List;

import yyh.guanganmen.common.FileUtil;
import yyh.guanganmen.db.Inhosptial_idAndHerbPairDB;
import yyh.jaccard.bean.Inhosptial_idAndHerbmedPairBean;


public class CreateInhosotial_idAndHerbPair implements Runnable {
	private String inPath;
	private String outPath;
	
	public CreateInhosotial_idAndHerbPair(){}
	
	public CreateInhosotial_idAndHerbPair(String inPath,String outPath){
		this.inPath = inPath;
		this.outPath = outPath;
	}
	
	public void run(){
		try {
			function(inPath, outPath);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	
	public void  function(String inPath,String outpath) throws IOException{
		List<Inhosptial_idAndHerbmedPairBean> list = getPairs(inPath);
		writeResult(list, outpath);
	}
	
	public List<Inhosptial_idAndHerbmedPairBean> getPairs(String path) throws IOException{
		List<Inhosptial_idAndHerbmedPairBean> list = new Inhosptial_idAndHerbPairDB().getPair(path);
		return list;
	} 
	
	public void writeResult(List<Inhosptial_idAndHerbmedPairBean> Beans,String outpath) throws IOException{
		BufferedWriter writer =  FileUtil.getWriter(outpath);
		for(Inhosptial_idAndHerbmedPairBean bean : Beans){
			writer.write(bean.getInhosptial_id()+"	"+bean.getHerbmedname());
			writer.newLine();
			writer.flush();
		}
		if(writer != null){
			writer.close();
		}
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}





